<template>
  <section>
    <!--工具条-->
    <el-form :inline="true" :model="searchForm" class="toolbar">
      <el-form-item label="用户名称">
        <el-input v-model="searchForm.orginzerName"></el-input>
      </el-form-item>
      <el-form-item label="申请日期">
        <div class="block">
          <el-date-picker v-model="searchForm.startTime" type="date" :picker-options="pickerOptions1" :editable="false" placeholder="选择日期"></el-date-picker> ~
          <el-date-picker v-model="searchForm.endTime" type="date" :picker-options="pickerOptions2" :editable="false" placeholder="选择日期"></el-date-picker>
        </div>
      </el-form-item>
      <el-form-item label="审核状态">
        <el-select v-model="searchForm.status" placeholder="请选择" clearable>
          <el-option v-for="item in status" :label="item.name" :key="item.code" :value="item.code"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="资料类型">
        <el-select v-model="searchForm.dataType" placeholder="请选择" clearable>
          <el-option v-for="item in dataType" :label="item.name" :key="item.code" :value="item.code"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核结果">
        <el-select v-model="searchForm.result" placeholder="请选择" clearable>
          <el-option v-for="item in result" :label="item.name" :key="item.code" :value="item.code"></el-option>
        </el-select>
      </el-form-item>
  <el-form-item>
    <el-button @click="search" type="info">查询</el-button>
  </el-form-item>
</el-form>
    <div class="divid-line"></div>
<!--列表-->
<template>
  <el-table :data="gridData" highlight-current-row v-loading="gridLoading" class="grid">
    <el-table-column label="序号" type="index" width="100">
    </el-table-column>
   <el-table-column label="用户名称" prop="userName" width="200" sortable>
   </el-table-column>
   <el-table-column label="申请时间" prop="applyTime" width="200" sortable>
     <template scope="scope">
       {{getDate(scope.row.applyTime)}}
     </template>
   </el-table-column>
    <el-table-column label="审核类型" prop="type"  sortable>
      <template scope="scope">
          {{getType1(scope.row.type)}}
      </template>
    </el-table-column>
    <el-table-column label="审核状态" prop="status" sortable>
      <template scope="scope">
        <el-tag :type="scope.row.status == 1 ? 'sucess' : 'danger'">
          {{getStatus(scope.row.status)}}
        </el-tag>
      </template>
    </el-table-column>
    <el-table-column label="审核结果" prop="result" sortable>
      <template scope="scope">
        <el-tag :type="scope.row.result == 1 ? 'danger' : 'sucess'">
          {{resultType(scope.row.result)}}
        </el-tag>
      </template>
    </el-table-column>
    <el-table-column label="操作" prop="remark">
      <template scope="scope">
        <el-button size="small" type="info" @click="checkData(scope.row)" v-if="scope.row.status == 2">查看详情</el-button>
        <el-button size="small" type="warning" @click="checkData(scope.row)" v-if="scope.row.status != 2">开始审核</el-button>
      </template>
    </el-table-column>
  </el-table>
  <!--分页-->
  <el-pagination class="pager" @size-change="pageSizeChange" @current-change="pageIndexChange" :current-page="pageIndex" :page-size="pageSize"
                 layout="total, sizes, prev, pager, next, jumper" :total="dataTotal">
  </el-pagination>
</template>
</section>
</template>
<script>
import enums from '../../common/Enum'
import DataUtil from '../../common/dataUtil'
import Config from '../../common/config'
export default {
  data () {
    let compareDate = (time, form, txt, type) => {
      let _cp1 = time.getTime() >= Date.now()
      let _cp2 = false
      let _input = this[form][txt]
      if (_input) {
        let _time = Date.parse(new Date(_input))
        if ((type == "s" && time.getTime() > _time) || (type == "e" && time.getTime() < _time)) {
          _cp2 = true
        }
      }
      return _cp1 || _cp2
    };

    return {
      searchForm:{
        name:'',
        type:'',
        startTime:'',
        endTime:'',
        dataType: '',
        status: '',
        result:'',
      },
      pageIndex: 1,
      pageSize: 10,
      dataTotal: 0,

      dataType:[{
        code: 1,
        name:'组织注册',
      },{
        code: 2,
        name:'募捐申请'
      },{
        code: 3,
        name:'募捐后续'
      }],
      status:[{
        code: 1,
        name:'未完成',
      },{
        code: 2,
        name:'已完成'
      }],
      result:[{
        code: 1,
        name:'通过',
      },{
        code: 2,
        name:'未通过'
      }],
      gridLoading: true,
      gridData:[],
//      acitvityVisible: false,
//      activityDialogLoading: false,
      pickerOptions1: {
        disabledDate(time) {
          return compareDate(time, "searchForm", "endTime", "s")
        }
      },
      pickerOptions2: {
        disabledDate(time) {
          return compareDate(time, "searchForm", "startTime", "e")
        }
      },
    }
  },
  methods: {
    getActivitySubject() {

        this.$http.post('activity/listActivitySubject',{}).then(response => {
            if (response.body.code == 1) {
                this.activitySubject = response.body.data;
            }
        });
   },
    pageSizeChange(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.bindGrid()
    },
    pageIndexChange(val) {
      this.pageIndex = val;
      this.bindGrid();
    },
  getDate(dates) {
    if(!dates){
      return '';
    }
    var myDate = new Date(dates);
    let minute=myDate.getMinutes();
    if(minute<10){
      minute="0"+minute;
    }
    let seconds=myDate.getSeconds()
    if(seconds<10){
      seconds="0"+seconds;
    }
    return myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate()+" "+myDate.getHours()+":"+minute+":"+seconds
  },
   getStatus(type) {

     let re = '未完成';
     this.status.forEach(obj => {
      if (obj.code == type) {
        re = obj.name;
        return re;
      }
    });
     return re;
   },
    getType1(type) {

      let re = '';
      this.dataType.forEach(obj => {
        if (obj.code == type) {
          re = obj.name;
          return re;
        }
      });
      return re;
    },
    resultType(type) {

      let re = '待审核';
      this.result.forEach(obj => {
        if (obj.code == type) {
          re = obj.name;
          return re;
        }
      });
      return re;
    },
     search() {
      this.bindGrid()
    },
    activityBack() {
      this.acitvityVisible = false;
      this.activityDialogLoading = false;
    },
    bindGrid() {
      this.gridLoading = true;
        // let _data = Object.assign(this.searchForm);
      this.searchForm.startTime = this.getDate(this.searchForm.startTime);
      this.searchForm.endTime = this.getDate(this.searchForm.endTime);
        let _data = Object.assign({
          pageSize: this.pageSize,
          pageNo: this.pageIndex,
          type : this.searchForm.dataType,
        }, this.searchForm);
        this.$http.post('schoolCheck/listCheckData', _data).then(response => {
          if (1 == response.body.code) {
            this.gridLoading = false;
            this.gridData = response.body.data.list;
            this.dataTotal = response.body.data.recordsTotal;
          } else {
            this.$message.error(body.message);
          }
        }).catch((e) =>{
          this.gridLoading = false;
        })
      },
    checkData(row) {
      window.open('#/SchoolCheckDetail?&id='+row.id + "&userId=" + row.userId + "&type=" + row.type);
    }
    },
    mounted: function () {
        this.bindGrid();
}
}
</script>
<style>
  .divid-line{
    height: 10px;
    background: #f1f2f7;
  }
</style>
